package model

import (
	"github.com/zhengchalei/gadmin/framework"
)

func init() {
	framework.AutoMigrate("ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统角色'", &SysRole{})
	if framework.DB.Find(&SysRole{}).First(&SysRole{Model: framework.Model{ID: 1}}).RowsAffected == 0 {
		framework.DB.Save(&SysRole{Model: framework.Model{ID: 1}, Name: "超级管理员", Code: "super-admin", Remark: "系统默认超级管理员"})
	}
	if framework.DB.Find(&SysRole{}).First(&SysRole{Model: framework.Model{ID: 2}}).RowsAffected == 0 {
		framework.DB.Save(&SysRole{Model: framework.Model{ID: 2}, Name: "管理员", Code: "admin", Remark: "系统默认管理员"})
	}
}

type SysRole struct {
	framework.Model
	Name   string `json:"name" form:"name" gorm:"not null;unique;comment:角色名;"`
	Code   string `json:"code" form:"code" gorm:"not null;unique;comment:角色编码;"`
	Remark string `json:"remark" form:"remark" gorm:"comment:角色描述;"`
	// join
	Users []SysUser `json:"users" gorm:"many2many:sys_user_role"`
}
